package com.zeedev.flyingsaucer.data;

import android.net.Uri;
import android.net.Uri.Builder;
import android.os.Parcel;
import android.os.Parcelable;
import mobi.zeedev.flyingsaucer.common.DataModule.FlyingSaucerConv;

public class BeerFilterProvider implements Parcelable {

	private String groupBy = null;
	private Uri host = null;
	private BeerFilter beerFilter = null;

	public BeerFilter getBeerFilter() {
		return beerFilter;
	}

	public void setBeerFilter(BeerFilter beerFilter) {
		this.beerFilter = beerFilter;
	}

	public BeerFilterProvider(String groupBy, Uri host) {
		super();
		this.groupBy = groupBy;
		this.host = host;
		beerFilter = new BeerFilter();
	}
	
	public Uri getHost() {
		return host;
	}

	public void setHost(Uri host) {
		this.host = host;
	}

	public Uri getUri() {
		Uri ret = null;
		
		Builder b = host.buildUpon();
		
		switch (beerFilter.tastedType) {
		case NOT_TASTED:
//			Command tastedCommand = new Command(MetaBeer.TASTED, String.valueOf(0), Operator.EQUAL, false);
			b.appendQueryParameter(FlyingSaucerConv.TASTED_BY, "false");
			break;
		case TASTED:
//			Command notTastedCommand = new Command(MetaBeer.TASTED, String.valueOf(1), Operator.EQUAL, false);
			b.appendQueryParameter(FlyingSaucerConv.TASTED_BY, "true");
			break;
		default:
		}

		
		switch (beerFilter.containerType) {

		case DRAUGHT:
//			Command draughtCommand = new Command(MetaBeer.DRAUGHT, String.valueOf(1), Operator.EQUAL, false);
			b.appendQueryParameter(FlyingSaucerConv.FILTER_CONTAINER, "draught");
			break;
		case BOTTLED:
//			Command bottledCommand = new Command(MetaBeer.BOTTLE, String.valueOf(1), Operator.EQUAL, false);
			b.appendQueryParameter(FlyingSaucerConv.FILTER_CONTAINER, "bottled");
			break;
		default: 
		}
		
		b.appendQueryParameter(FlyingSaucerConv.ACTIVE_BY, "true");
		b.appendQueryParameter(FlyingSaucerConv.GROUP_BY, groupBy);
		b.appendQueryParameter(FlyingSaucerConv.SORT_BY, groupBy + " asc");
		
		
		ret = b.build();
		
		return ret;
	}

	public String getGroupBy() {
		return groupBy;
	}

	public void setGroupBy(String groupBy) {
		this.groupBy = groupBy;
	}

	
	
	@Override
	public int describeContents() {
		return 0;
	}
	

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeSerializable(this.beerFilter);
		out.writeParcelable(this.host, 0);
		out.writeString(groupBy);
	}
	
	public static final Parcelable.Creator<BeerFilterProvider> CREATOR = new Parcelable.Creator<BeerFilterProvider>() {
		@Override
		public BeerFilterProvider createFromParcel(Parcel in) {
			return new BeerFilterProvider(in);
		}

		@Override
		public BeerFilterProvider[] newArray(int size) {
			return new BeerFilterProvider[size];
		}
	};

	private BeerFilterProvider(Parcel in) {
		this.beerFilter = (BeerFilter) in.readSerializable();
		this.host = in.readParcelable(null);
		this.groupBy = in.readString();
	}
	
	
	
	
}
